package com.lagou.edu.course.remote;

import com.lagou.edu.course.api.dto.CoursePlayHistoryDTO;
import com.lagou.edu.course.entity.CoursePlayHistory;
import com.lagou.edu.course.service.ICoursePlayHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * TODO
 *
 * @author lm
 * @since 2021/11/2 10:08
 */
@Slf4j
@Service
public class CoursePlayHistoryService {
    @Autowired
    ICoursePlayHistoryService iCoursePlayHistoryService;

    public CoursePlayHistoryDTO getCoursePlayHistoryByLessonId(Integer lessonId, Integer userId) {
        List<CoursePlayHistory> coursePlayHistoryList = iCoursePlayHistoryService.lambdaQuery()
                .eq(CoursePlayHistory::getLessonId, lessonId)
                .eq(CoursePlayHistory::getUserId, userId)
                .eq(CoursePlayHistory::getIsDel, Boolean.FALSE)
                .list();

        if (CollectionUtils.isEmpty(coursePlayHistoryList)) {
            return null;
        }
        CoursePlayHistory coursePlayHistory = coursePlayHistoryList.get(0);
        CoursePlayHistoryDTO coursePlayHistoryDTO = new CoursePlayHistoryDTO();
        BeanUtils.copyProperties(coursePlayHistory, coursePlayHistoryDTO);
        return coursePlayHistoryDTO;
    }

    public void saveCourseHistoryNode(CoursePlayHistoryDTO playHistoryDTO) {
        //iCoursePlayHistoryService.saveCourseHistoryNode(playHistoryDTO);
    }
}
